import time
import vec

WIDTH = 250
HEIGHT = 250

BACK_COLOR = (0, 0, 127)
CIRCLE_COLOR = (0, 200, 0)

lastTime = time.time()
deltaTime = 0

way_pt = [vec.Vec2(50, 50), vec.Vec2(50, 200), vec.Vec2(200, 200), vec.Vec2(200, 50), vec.Vec2(50, 50)]

next_pt_index = 1

p = 0
pspd = 0.2

class MyCircle:
    def __init__(self, pos, r):
        self.pos = pos
        self.r = r

    def Draw(self):
        screen.draw.filled_circle((self.pos.x, self.pos.y), self.r, CIRCLE_COLOR)

c = MyCircle(way_pt[0], 30)

def on_key_down(key):
    if key == keys.ESCAPE:
        quit()

def on_mouse_down(pos):
    print("mouse_down", pos)

def on_mouse_up(pos):
    print("mouse_up", pos)

def move(start_pt, end_pt):
    global p, c
    has_finished = False
    p += pspd * deltaTime
    if p > 1.0:    
        p = 1.0
        has_finished = True

    c.pos = start_pt * (1 - p) + end_pt * p

    return has_finished

def update():
    global lastTime, deltaTime, next_pt_index, p
    curTime = time.time()
    deltaTime = curTime - lastTime
    lastTime = curTime
    
    if next_pt_index >= len(way_pt): 
        return  
    
    if move(way_pt[next_pt_index - 1], way_pt[next_pt_index]) == True:
        next_pt_index += 1
        p = 0

def draw():
    screen.fill(BACK_COLOR)
    c.Draw()